'use strict';

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

Vue.component('category-lst', {
    props: ['module', 'add_url', 'lst_url', 'mod_url', 'del_url', 'preview_url'],
    template: '\n<table width="98%" border="0" class="table table-bordered">\n  <tbody>\n    <tr>\n      <td>\u5206\u7C7BID</td>\n      <td>\u8DEF\u5F84</td>\n      <td>\u540D\u79F0</td>\n      <td>\u7F16\u8F91</td>\n      <td>\u5220\u9664</td>\n    </tr>\n    <tr v-for="(item,index) in category_select">\n      <td>{{item.catid}}</td>\n      <td v-html="item.cat_pos"></td>\n      <td>{{\'&nbsp;&nbsp;&nbsp;&nbsp;\'.repeat(item.lev)+\'\u2516\u2500&nbsp;\'+item.catname}}</td>\n      <td>\n      <el-button\n              size="mini"\n              @click="handleEdit(index,item)">\u7F16\u8F91</el-button>\n            </td>\n      <td>\n      <el-button\n              size="mini"\n              type="danger"\n              @click="handleDelete(index, item)">\u5220\u9664</el-button>\n</td>\n    </tr>\n  </tbody>\n</table>\n',
    data: function data() {
        return {
            category_select: []
        };
    },

    methods: {
        //编辑
        handleEdit: function handleEdit(index, row) {
            this.$forward('/admin/' + this.module + '/category_mod?catid=' + row.catid);
        },

        //删除
        handleDelete: function handleDelete(index, row) {
            var _this = this;

            this.$confirm('确定要删除吗？', '系统提醒', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
                var response, data;
                return regeneratorRuntime.wrap(function _callee$(_context) {
                    while (1) {
                        switch (_context.prev = _context.next) {
                            case 0:
                                _context.prev = 0;
                                _context.next = 3;
                                return axios.post(_this.del_url, { catid: row.catid });

                            case 3:
                                response = _context.sent;
                                data = response.data;

                                if (parseInt(data.code) > 0) {
                                    _this.$message({
                                        type: 'success',
                                        message: '删除成功!',
                                        duration: 1000
                                    });
                                    setTimeout(function () {
                                        location.reload();
                                    }, 1000);
                                } else {
                                    _this.$message({
                                        type: 'error',
                                        message: data.msg
                                    });
                                }
                                _context.next = 11;
                                break;

                            case 8:
                                _context.prev = 8;
                                _context.t0 = _context['catch'](0);

                                _this.$message.error(_context.t0.toString());

                            case 11:
                            case 'end':
                                return _context.stop();
                        }
                    }
                }, _callee, _this, [[0, 8]]);
            }))).catch(function () {});
        }
    },
    created: function created() {},
    mounted: function () {
        var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
            var response, data;
            return regeneratorRuntime.wrap(function _callee2$(_context2) {
                while (1) {
                    switch (_context2.prev = _context2.next) {
                        case 0:
                            _context2.prev = 0;
                            _context2.next = 3;
                            return axios.post(this.lst_url, {});

                        case 3:
                            response = _context2.sent;
                            data = response.data;

                            if (parseInt(data.code) > 0) {
                                this.category_select = data.data;
                            } else {
                                this.$message.error(data.msg);
                            }
                            _context2.next = 11;
                            break;

                        case 8:
                            _context2.prev = 8;
                            _context2.t0 = _context2['catch'](0);

                            this.$message.error(_context2.t0.toString());

                        case 11:
                        case 'end':
                            return _context2.stop();
                    }
                }
            }, _callee2, this, [[0, 8]]);
        }));

        function mounted() {
            return _ref2.apply(this, arguments);
        }

        return mounted;
    }()
});